/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springblade.modules.monitor.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.modules.monitor.dto.ChartDTO;
import org.springblade.modules.monitor.pojo.ExsiVO;
import org.springblade.modules.monitor.pojo.ServerDetailVO;
import org.springblade.modules.monitor.pojo.VMMachineVO;
import org.springblade.modules.monitor.service.IHostInfoService;
import org.springblade.modules.monitor.vo.HostInfoVO;
import org.springblade.modules.monitor.vo.ItemChartResult;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 *  控制器
 *
 * @author Blade
 * @since 2020-05-17
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-monitor/serverinfo")
@Api(value = "服务器信息", tags = "服务器信息接口")
public class ServerInfoController extends BladeController {

	private IHostInfoService hostInfoService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "实体机详情", notes = "interfaceid")
	public R<ServerDetailVO> detail(Long interfaceid) {
		//获取服务器实际信息
		ServerDetailVO detail = hostInfoService.getDetail(interfaceid);
		return R.data(detail);
	}

	/**
	 * 获取EXSI信息
	 */
	@GetMapping("/exsidetail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "ESXI详情", notes = "interfaceid")
	public R<ExsiVO> getEXSIdetail(Long interfaceid) {
		//获取服务器实际信息
		ExsiVO exsiVO = hostInfoService.getEXSIdetail(interfaceid);
		return R.data(exsiVO);
	}

	/**
	 * 获取虚拟机信息
	 */
	@GetMapping("/vmdetail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "虚拟机详情", notes = "interfaceid")
	public R<VMMachineVO> getVMdetail(Long interfaceid) {
		//获取服务器实际信息
		VMMachineVO detail = hostInfoService.getVMdetail(interfaceid);
		return R.data(detail);
	}


	/**
	 * 获取CPU、内存使用情况
	 */
	@GetMapping("/serverCpuOrMemoryInfo")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "服务器CPU、内存使用趋势（折线图）等", notes = "获取服务器CPU、内存使用情况")
	public R<List<ItemChartResult>> getCpuOrMemoryInfo(ChartDTO chartDTO) {
		List<ItemChartResult> chartDTOList = hostInfoService.getCpuOrMemoryInfo(chartDTO);
		return R.data(chartDTOList);
	}

	/**
	 * 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiImplicitParams({
		@ApiImplicitParam(name = "host", value = "服务器名称", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "status", value = "是否可用", paramType = "query", dataType = "int")
	})
	@ApiOperation(value = "分页", notes = "传入HostInfoVO")
	public R<IPage<HostInfoVO>> list(@ApiIgnore HostInfoVO hostInfoVO, Query query) {
		IPage<HostInfoVO> pages = hostInfoService.selectHostInfoPage(Condition.getPage(query), hostInfoVO);
		return R.data(pages);
	}

}
